package com.exam.sacrifice.ui;

import android.graphics.Bitmap;
import android.view.View;

import com.exam.commonbiz.base.BaseFragment;
import com.exam.commonbiz.base.BaseViewModel;
import com.exam.commonbiz.base.BasicApplication;
import com.exam.commonbiz.bean.UserInfo;
import com.exam.commonbiz.util.OnFastClickListener;
import com.exam.commonbiz.util.ToastUtil;
import com.exam.sacrifice.R;
import com.exam.sacrifice.databinding.FragmentMineBinding;
import com.exam.sacrifice.ui.mine.AddressListActivity;
import com.exam.sacrifice.ui.mine.FeedbackActivity;
import com.exam.sacrifice.ui.mine.RechargeCenterActivity;
import com.exam.sacrifice.ui.mine.SettingActivity;
import com.exam.sacrifice.ui.mine.UserInfoActivity;
import com.exam.sacrifice.util.BitmapCacheUtils;
import com.exam.sacrifice.viewmodel.IUserCallBack;
import com.exam.sacrifice.viewmodel.UserViewModel;

public class MineFragment extends BaseFragment<UserViewModel, FragmentMineBinding> implements IUserCallBack {

    public static MineFragment newInstance() {
        MineFragment fragment = new MineFragment();
        return fragment;
    }

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_mine;
    }

    @Override
    public void initData() {

        mViewModel.setUserCallBack(this);
        binding.ivAvatar.setOnClickListener(new OnFastClickListener() {
            @Override
            public void onFastClick(View v) {
                actionStart(UserInfoActivity.class);
            }
        });

        binding.tvUserinfo.setOnClickListener(new OnFastClickListener() {
            @Override
            public void onFastClick(View v) {
                actionStart(UserInfoActivity.class);
            }
        });

        binding.llJisijilu.setOnClickListener(new OnFastClickListener() {
            @Override
            public void onFastClick(View v) {
                String url = "http://fete.wqsoftware.cn/#/pages/worshipList/worshipList";
                X5WebViewActivity.start(context, "祭祀记录", url);
            }
        });

        binding.llShoucang.setOnClickListener(new OnFastClickListener() {
            @Override
            public void onFastClick(View v) {
                ToastUtil.getInstance().showToast("功能开发中");
            }
        });

        binding.llRili.setOnClickListener(new OnFastClickListener() {
            @Override
            public void onFastClick(View v) {
                actionStart(JiSiRiLiActivity.class);
            }
        });

        binding.llJipinku.setOnClickListener(new OnFastClickListener() {
            @Override
            public void onFastClick(View v) {
                ToastUtil.getInstance().showToast("功能开发中");
            }
        });

        binding.llWaitpay.setOnClickListener(new OnFastClickListener() {
            @Override
            public void onFastClick(View v) {
                ToastUtil.getInstance().showToast("功能开发中");
            }
        });

        binding.llHandle.setOnClickListener(new OnFastClickListener() {
            @Override
            public void onFastClick(View v) {
                ToastUtil.getInstance().showToast("功能开发中");
            }
        });

        binding.llComplete.setOnClickListener(new OnFastClickListener() {
            @Override
            public void onFastClick(View v) {
                ToastUtil.getInstance().showToast("功能开发中");
            }
        });

        binding.llRefund.setOnClickListener(new OnFastClickListener() {
            @Override
            public void onFastClick(View v) {
                ToastUtil.getInstance().showToast("功能开发中");
            }
        });

        binding.llAddress.setOnClickListener(new OnFastClickListener() {
            @Override
            public void onFastClick(View v) {
                actionStart(AddressListActivity.class);
            }
        });

        binding.llRecharge.setOnClickListener(new OnFastClickListener() {
            @Override
            public void onFastClick(View v) {
                actionStart(RechargeCenterActivity.class);
            }
        });

        binding.llAdvice.setOnClickListener(new OnFastClickListener() {
            @Override
            public void onFastClick(View v) {
                actionStart(FeedbackActivity.class);
            }
        });

        binding.llSetting.setOnClickListener(new OnFastClickListener() {
            @Override
            public void onFastClick(View v) {
                actionStart(SettingActivity.class);
            }
        });

        mViewModel.getUserInfo();
    }

    @Override
    public void onResume() {
        super.onResume();
        Bitmap bitmap = BitmapCacheUtils.loadBitmapFromCache(context, "avatar.png");
        if (bitmap != null) {
            binding.ivAvatar.setImageBitmap(bitmap);
        }
    }

    @Override
    protected void loadData() {

    }

    @Override
    public void onUserInfoCallBack(UserInfo userInfo) {
        if (userInfo == null){
            return;
        }
        binding.tvName.setText(userInfo.nickName);
    }
}
